/*
 * stm32f10x_adf.h
 *
 *  Created on: 01.06.2012
 *      Author: Roma Jam
 */

#include "adf.h"

#ifndef STM32F10X_ADF_H_
#define STM32F10X_ADF_H_

#define REGISTER0_ADDR          0b000
#define REGISTER1_ADDR          0b001
#define REGISTER2_ADDR          0b010
#define REGISTER3_ADDR          0b011
#define REGISTER4_ADDR          0b100
#define REGISTER5_ADDR          0b101

typedef enum
{
    Dual_modulus_prescaler4_5 = 0b0,
    Dual_modulus_prescaler8_9 = 0b1,
}ADFDual_Modulus_prescaler_TypeDef;

typedef enum
{
    NoiseMode_LowNoiseMode = 0x0,
    NoiseMode_LowSpurMode = 0x3,
}ADFNoise_mode_TypeDef;

typedef enum
{
    Muxout_ThreeStateOutput = 0x0,
    Muxout_PowerSupply = 0x1,
    Muxout_GroundSupply = 0x2,
    Muxout_R_dividerOutput = 0x3,
    Muxout_N_dividerOutput = 0x4,
    Muxout_AnalogLockDetect = 0x5,
    Muxout_DigitalLockDetect = 0x6,
}ADFMuxout_TypeDef;

typedef enum
{
    RefDoubler_Disabled = 0,
    RefDoubler_Enabled = 1,
}ADFReference_doubler_TypeDef;

typedef enum
{
    RefDivider_Disabled = 0,
    RefDivider_Enabled = 1,
}ADFReference_divide_2_TypeDef;

typedef enum
{
    DoubleBuffer_Disabled = 0,
    DoubleBuffer_Enabled = 1,
}ADFDoubled_buffer_TypeDef;

typedef enum
{
    ChargePumpCurrent_310uA = 0x0,
    ChargePumpCurrent_630uA = 0x1,
    ChargePumpCurrent_940uA = 0x2,
    ChargePumpCurrent_1250uA = 0x3,
    ChargePumpCurrent_1560uA = 0x4,
    ChargePumpCurrent_1880uA = 0x5,
    ChargePumpCurrent_2190uA = 0x6,
    ChargePumpCurrent_2500uA = 0x7,
    ChargePumpCurrent_2810uA = 0x8,
    ChargePumpCurrent_3130uA = 0x9,
    ChargePumpCurrent_3440uA = 0xa,
    ChargePumpCurrent_3750uA = 0xb,
    ChargePumpCurrent_4060uA = 0xc,
    ChargePumpCurrent_4330uA = 0xd,
    ChargePumpCurrent_4690uA = 0xe,
    ChargePumpCurrent_5000uA = 0xf,

}ADFCharge_pump_Current_set_TypeDef;
typedef enum
{
    LDF_FRAC_N = 0,
    LDF_INT_N = 1,
}ADFFrac_lock_detect_TypeDef;

typedef enum
{
    LDP_10ns = 0,
    LDP_6ns= 1,
}ADFPrecision_lock_detect_TypeDef;

typedef enum
{
    PdPolarity_Negative = 0,
    PdPolarity_Positive = 1,
}ADFPD_polarity_TypeDef;

typedef enum
{
    PowerDown_Disabled = 0,
    PowerDown_Enabled = 1,
}ADFPower_down_TypeDef;

typedef enum
{
    CpThreeState_Disabled = 0,
    CpThreeState_Enabled = 1,
}ADFCP_three_state_TypeDef;

typedef enum
{
    CounterReset_Disabled = 0,
    CounterReset_Enabled = 1,
}ADFCounter_reset_TypeDef;

typedef enum
{
    CycleSlipReduction_Disabled = 0,
    CycleSlipReduction_Enabled = 1,
}ADFCycle_slip_reduction_TypeDef;

typedef enum
{
    ClockDividerMode_off = 0b00,
    ClockDividerMode_FastLockEnable = 0b01,
    ClockDividerMode_ResynchEnable = 0b11,
}ADFClock_divider_mode_TypeDef;

typedef enum
{
    FeedbackSelect_Divided = 0,
    FeedbackSelect_Fundamental = 1,
}ADFFeedback_select_TypeDef;

typedef enum
{
    RfDivider_1 = 0b000,
    RfDivider_2 = 0b001,
    RfDivider_4 = 0b010,
    RfDivider_8 = 0b011,
    RfDivider_16 = 0b100,
}ADFRF_Divider_TypeDef;

typedef enum
{
    VcoPowerMode_PoweredUp = 0b0,
    VcoPowerMode_PoweredDown = 0b1,
}ADFVCO_Powered_down_TypeDef;

typedef enum
{
    Mute_Disabled = 0b0,
    Mute_Enabled = 0b1,
}ADFMute_TypeDef;

typedef enum
{
    AuxOutputSelect_DividedOutput = 0,
    AuxOutputSelect_Fundamental = 1,
}ADFAUX_Output_select_TypeDef;

typedef enum
{
    AuxEnabler_Disabled = 0,
    AuxEnabler_Enabled = 1,
}ADFAUX_Out_TypeDef;

typedef enum
{
    AuxOutputPower_Dec4 = 0b00,
    AuxOutputPower_Dec1 = 0b01,
    AuxOutputPower_Inc2 = 0b10,
    AuxOutputPower_Inc5 = 0b11,
}ADFAUX_Output_power_TypeDef;

typedef enum
{
    RfOutput_Disabled = 0b0,
    RfOutput_Enabled = 0b1,
}ADFRF_Output_enable_TypeDef;

typedef enum
{
    OutputPower_Dec4 = 0b00,
    OutputPower_Dec1 = 0b01,
    OutputPower_Inc2 = 0b10,
    OutputPower_Inc5 = 0b11,
}ADFOutput_power_TypeDef;

typedef enum
{
    LockDetectPinMode_Low = 0b00,
    LockDetectPinMode_DigitalLockDetect = 0b01,
    LockDetectPinMode_High = 0b11,
}ADFLD_Pin_mode_TypeDef;

typedef struct
{
    uint16_t ADF_INT;

    uint16_t ADF_FRAC;

    ADFDual_Modulus_prescaler_TypeDef ADF_Prescaler;

    uint16_t ADF_PHASE;

    uint16_t ADF_MOD;

    ADFNoise_mode_TypeDef ADF_NoiseMode;

    ADFMuxout_TypeDef ADF_Muxout;

    ADFReference_doubler_TypeDef ADF_RefDoubler;

    ADFReference_divide_2_TypeDef ADF_RefDivider;

    uint16_t ADF_R_COUNTER;

    ADFDoubled_buffer_TypeDef ADF_DoubleBuffer;

    ADFCharge_pump_Current_set_TypeDef ADF_ChargePumpCurrent;

    ADFFrac_lock_detect_TypeDef ADF_LDF;

    ADFPrecision_lock_detect_TypeDef ADF_LDP;

    ADFPD_polarity_TypeDef ADF_PdPolarity;

    ADFPower_down_TypeDef ADF_PowerDown;

    ADFCP_three_state_TypeDef ADF_CpThreeState;

    ADFCounter_reset_TypeDef ADF_CounterReset;

    ADFCycle_slip_reduction_TypeDef ADF_CycleSlipReduction;

    ADFClock_divider_mode_TypeDef ADF_ClockDividerMode;

    uint16_t ADF_CLOCK_DIV;

    ADFFeedback_select_TypeDef ADF_FeedbackSelect;

    ADFRF_Divider_TypeDef ADF_RfDivider;

    uint16_t ADF_BAND_CLOCK_DIV;

    ADFVCO_Powered_down_TypeDef ADF_VcoPowerMode;

    ADFMute_TypeDef ADF_Mute;

    ADFAUX_Output_select_TypeDef ADF_AuxOutputSelect;

    ADFAUX_Out_TypeDef ADF_AuxEnabler;

    ADFAUX_Output_power_TypeDef ADF_AuxOutputPower;

    ADFRF_Output_enable_TypeDef ADF_RfOutput;

    ADFOutput_power_TypeDef ADF_OutputPower;

    ADFLD_Pin_mode_TypeDef ADF_LockDetectPinMode;
}ADF_InitTypeDef;

class ADFSetup_t {
private:
    uint32_t REGISTER0_SEQ, REGISTER1_SEQ, REGISTER2_SEQ, REGISTER3_SEQ, REGISTER4_SEQ, REGISTER5_SEQ;
public:
    void Setup(int FRAC_LIT, AdfDescriptions_t *PAdf);
};
extern class ADFSetup_t AdfChip;

#endif /* STM32F10X_ADF_H_ */
